package com.gnerv.plug.maven.action;

import com.gnerv.plug.maven.model.DependencyInfo;
import com.gnerv.plug.maven.model.DependencyInfoList;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.io.IOException;

/**
 * <p>
 *
 * @Description: [刷新maven]
 * @Author: [Gnerv]
 * @CreateDate: [2020/08/17]
 * </p>
 */
public class RefreshDependencyAction extends AnAction {

    public RefreshDependencyAction() {
        super();
    }

    public RefreshDependencyAction(String text, String description, Icon icon) {
        super(text, description, icon);
    }

    @Override
    public void actionPerformed(@NotNull AnActionEvent anActionEvent) {
        OkHttpClient client = new OkHttpClient();

        Request request = new Request.Builder()
                .url("http://39.100.130.232:8911/plugin/maven/list")
                .build();
        try (Response response = client.newCall(request).execute()) {
            DependencyInfoList.initAction(response.body().string());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


}
